/*
 * @Author: 冷澄峰 2362919153@qq.com
 * @Date: 2022-11-28 10:09:39
 * @LastEditors: 冷澄峰 2362919153@qq.com
 * @LastEditTime: 2023-02-08 15:38:30
 * @FilePath: \a-vite-project\vite.config.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import AutoImport from 'unplugin-auto-import/vite'
import path from 'path'
import Components from 'unplugin-vue-components/vite'
import {
  ElementPlusResolver,
} from 'unplugin-vue-components/resolvers'

export default defineConfig({
  plugins: [
    vue(),
    AutoImport({
      // 可以自定义文件生成的位置，默认是根目录下，使用ts的建议放src目录下
      dts: 'src/auto-imports.d.ts',
      imports: ['vue', 'vue-router'],
      //自动导入element
      resolvers: [ElementPlusResolver()]
    }),
    Components({
      resolvers: [ElementPlusResolver()]
    })
  ],
  resolve: {
    alias: {
      '~': path.resolve(__dirname, './'),
      '@': path.resolve(__dirname, 'src')
    }
  },
  // 设置跨域
  server: {
    open: true, // 启动自动打开浏览器
    host: '0.0.0.0', //启动本地ip
    port: 5176,
    // secure:false,
    // proxy: {
    //   '/api': {
    //     target: 'http://localhost:5176/',
    //     ws: false,
    //     changeOrigin: true,
    //     rewrite: (path) => path.replace(/^\/api/, '')
    //   }
    // }
  },
  //设置全局变量
  css: {
    preprocessorOptions: {
      scss: {
        additionalData: `@import "./src/assets/css/common.scss";`
      }
    }
  }
})
